import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    redirect: '/monitoring'
  },
  {
    path: '/roma-pools',
    name: 'RomaPools',
    component: () => import('@/views/RomaPools/index.vue'),
    meta: { title: 'ROMA 资源池' }
  },
  {
    path: '/experiment-templates',
    name: 'ExperimentTemplates',
    component: () => import('@/views/ExperimentTemplates/index.vue'),
    meta: { title: '实验模板管理' }
  },
  {
    path: '/experiment-templates/create',
    name: 'TemplateCreate',
    component: () => import('@/views/ExperimentTemplates/TemplateEdit.vue'),
    meta: { title: '创建实验模板' }
  },
  {
    path: '/experiment-templates/:id',
    name: 'TemplateDetail',
    component: () => import('@/views/ExperimentTemplates/TemplateDetail.vue'),
    meta: { title: '模板详情' }
  },
  {
    path: '/experiment-templates/:id/edit',
    name: 'TemplateEdit',
    component: () => import('@/views/ExperimentTemplates/TemplateEdit.vue'),
    meta: { title: '编辑模板' }
  },
  {
    path: '/workflow-templates',
    name: 'WorkflowTemplates',
    component: () => import('@/views/WorkflowTemplates/index.vue'),
    meta: { title: '工作流模板管理' }
  },
  {
    path: '/workflow-templates/:id',
    name: 'WorkflowTemplateDetail',
    component: () => import('@/views/WorkflowTemplates/detail.vue'),
    meta: { title: '模板详情' }
  },
  {
    path: '/workflow-templates/:id/edit',
    name: 'WorkflowTemplateEditor',
    component: () => import('@/views/WorkflowTemplates/editor.vue'),
    meta: { title: '编辑工作流模板' }
  },
  {
    path: '/workflow-templates/:id/versions',
    name: 'WorkflowTemplateVersionHistory',
    component: () => import('@/views/WorkflowTemplates/VersionHistory.vue'),
    meta: { title: '版本历史' }
  },
  {
    path: '/workflow-templates/:id/versions/:version',
    name: 'WorkflowTemplateVersionDetail',
    component: () => import('@/views/WorkflowTemplates/VersionDetail.vue'),
    meta: { title: '版本详情' }
  },
  {
    path: '/workflow-templates/:id/diff',
    name: 'WorkflowTemplateVersionDiff',
    component: () => import('@/views/WorkflowTemplates/VersionDiff.vue'),
    meta: { title: '版本对比' }
  },
  // {
  //   path: '/workflows',
  //   name: 'Workflows',
  //   component: () => import('@/views/Workflows/index.vue'),
  //   meta: { title: '工作流管理（旧）' }
  // },
  // {
  //   path: '/workflows/:id',
  //   name: 'WorkflowDetail',
  //   component: () => import('@/views/Workflows/detail.vue'),
  //   meta: { title: '工作流详情（旧）' }
  // },
  // {
  //   path: '/workflows/:id/edit',
  //   name: 'WorkflowEditor',
  //   component: () => import('@/views/Workflows/editor.vue'),
  //   meta: { title: '工作流编辑器（旧）' }
  // },
  {
    path: '/workflows/instances/:id',
    name: 'WorkflowInstanceDetail',
    component: () => import('@/views/Workflows/instance-detail.vue'),
    meta: { title: '工作流实例详情' }
  },
  {
    path: '/monitoring',
    name: 'Monitoring',
    component: () => import('@/views/Monitoring/index.vue'),
    meta: { title: '执行监控面板' }
  },
  {
    path: '/workflow-instances/create',
    name: 'WorkflowInstanceCreate',
    component: () => import('@/views/Monitoring/instance-editor.vue'),
    meta: { title: '创建工作流实例' }
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = `${to.meta.title} - BMC实验管理平台`
  }
  next()
})

export default router
